<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<script type="text/javascript" src="js/jquery.itextclear.js"></script>
<script type="text/javascript">
    $(document).ready(function() {
        $('input[type=text], input[type=password], input[type=url], input[type=email], input[type=number], textarea', '.form').iTextClear();
    });
</script>
<!-- jQplot CSS -->

<link rel="stylesheet" media="screen" href="${ctx}/css/Tree.css"/>
<!-- jQplot CSS END -->

<!-- DATATABLES CSS -->
<link rel="stylesheet" media="screen" href="lib/datatables/css/vpad.css"/>
<script type="text/javascript" src="lib/datatables/js/jquery.dataTables.js"></script>
<!-- DATATABLES CSS END -->

<h1 class="page-title">合同版本设置</h1>

<div class="container_12 clearfix leading">

    <div class="tabs side grid_8 leading">

        <div class="grid_12">
            <div id="demo" class="clearfix">
                <table class="display" id="example">
                    <thead>
                    <tr>
                        <th>选择</th>
                        <th>名称</th>
                        <th>版本</th>
                        <th>上传时间</th>
                        <s:if test="#request.operation == 'list'"><th>审核</th></s:if>
                        <th>状态</th>
                        <s:if test="#request.operation == 'set'"><th>操作</th></s:if>
                    </tr>
                    </thead>
                    <tbody>
                    <s:if test="#request.versions == null or #request.versions.size() == 0">
                    <tr><td>没有数据</td></tr>
                    </s:if>

                    <s:iterator value="#request.versions" var="v" status="sta">
                    <s:if test="#sta.even"> <tr class="gradeA"> </s:if><s:else><tr class="gradeC"></s:else>
                        <td><input type="checkbox" name="checkbox_version" value="${v.id}"/></td>
                        <td>${v.contractName}</td>
                        <td>1.${v.contractVer}</td>
                        <td><s:date name="#request.v.create_date" format="yyyy-MM-dd"/></td>
                        <s:if test="#request.operation == 'set'">
                        <td><a class="button">
                            <s:if test="#request.v.auditStatus.toString() == 'wait_audit'">
                            <span style="background:url(${ctx}/images/img/information.png)" class="icon icon-ok">&nbsp;</span>${v.auditStatus.name}
                            </s:if>
                            <s:elseif test="#request.v.auditStatus.toString() == 'reject_audit'">
                                <span style="background:url(${ctx}/images/img/delete.png)" class="icon icon-ok">&nbsp;</span>${v.auditStatus.name}
                            </s:elseif>
                            <s:else>
                                <span style="background:url(${ctx}/images/img/accept.png)" class="icon icon-ok">&nbsp;</span>${v.auditStatus.name}
                            </s:else>
                        </a></td>
                        <td>
                            <a class="button" href="#contract/version_edit.xhtml?version.id=${v.id}&t=<%=new java.util.Date().getTime()%>"> <span style="background:url(${ctx}/images/img/page_edit.png)" class="icon">&nbsp;</span>修改</a>
                            <a class="button"><div onclick="deleteVersion(${v.id})"><span style="background:url(${ctx}/images/img/delete.png)" class="icon">&nbsp;</span>删除</div></a>
                        </td>
                        </s:if>
                        <s:elseif test="#request.operation == 'audit'">
                        <td><a class="button" href="#contract/version_audit_detail.xhtml?versionId=${v.id}&t=<%=new java.util.Date().getTime()%>"><span style="background:url(${ctx}/images/img/script_error.png)" class="icon icon-ok">&nbsp;</span>${v.auditStatus.name}</a></td>
                        </s:elseif>
                        <s:elseif test="#request.operation == 'list'">
                        <td><a class="button">
                            <s:if test="#request.v.auditStatus.toString() == 'wait_audit'">
                            <span style="background:url(${ctx}/images/img/information.png)" class="icon icon-ok">&nbsp;</span>${v.auditStatus.name}
                            </s:if>
                            <s:elseif test="#request.v.auditStatus.toString() == 'reject_audit'">
                                <span style="background:url(${ctx}/images/img/delete.png)" class="icon icon-ok">&nbsp;</span>${v.auditStatus.name}
                            </s:elseif>
                            <s:else>
                                <span style="background:url(${ctx}/images/img/accept.png)" class="icon icon-ok">&nbsp;</span>${v.auditStatus.name}
                            </s:else>
                        </a></td>
                        <s:if test="#request.v.cancel">
                        <td><a class="button"><span style="background:url(${ctx}/images/img/delete.png)" class="icon icon-ok">&nbsp;</span>禁用</a></td>
                        </s:if>
                        <s:else>
                        <td><a class="button"><span style="background:url(${ctx}/images/img/accept.png)" class="icon icon-ok">&nbsp;</span>启用</a></td>
                        </s:else>
                        </s:elseif>
                        <s:else><td>&nbsp;</td></s:else>
                    </s:iterator>
                    </tbody>
                </table>
            </div>
            <div class="form-action clearfix">
                <p>
                    <%@ include file="/WEB-INF/pages/common/main_pager.jsp" %>
                </p>
                <s:if test="#request.operation == 'set'">
                <p>
                    <input type="checkbox" id="check_all" value="1" onchange="checkAll(this, 'checkbox_version')"/><label for="check_all">全选</label>
                    <button class="button" type="button" onclick="deleteVersions()">批量删除</button>
                    <a class="button" href="#contract/version_edit.xhtml?t=<%=new java.util.Date().getTime()%>"><span style="background:url(${ctx}/images/img/add.png)" class="icon">&nbsp;</span>添加</a>
                </p>
                </s:if>
            </div>
        </div>
    </div>
</div>

<div class="clear"></div>


<script type="text/javascript" src="js/Tree.js"></script>
<script type="text/javascript">
    function deleteVersion(id){
        if(confirm("确定要删除本条数据吗？")){
            doDeleteVersions(id);
        }
    }
    function deleteVersions(){
        var checkIds = new Array();
        $("input[type='checkbox'][name='checkbox_version']").each(function(){
            if(this.checked){
                checkIds.push(this.value);
            }
        });
        if(checkIds.length == 0){
            return;
        }
        if(confirm("确定要删除选中的数据吗？")){
            doDeleteVersions(checkIds.join(","))
        }
    }

    function doDeleteVersions(ids){
        var url = "${ctx}/contract/version_remove.xhtml";
        refreshListContent(url, {"organizationId":"${organizationId}", "ids":ids, "operation":"${operation}"});
    }
</script>